package com.helen.exam03.Controller;/*
 *@Author: helen
 *@Date:   2021/5/11 15:59
 *@Description:
 */

import com.helen.exam03.Service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/data")
public class CsvController {

    @Autowired
    private DataService dataService;

    @RequestMapping("/show")
    public String show(Model model){
        List list = dataService.getAllData();
        int Total = dataService.getSum();
        int diff = dataService.getDiffData();
        model.addAttribute("regionList", list);
        model.addAttribute("Total", Total);
        model.addAttribute("diff", diff);
        return "show";
    }

    @RequestMapping("/showChina")
    public String showChina(Model model){
        List list = dataService.FindChineseData();
        int Total = dataService.getSumOne("中国");
        int diff = dataService.getDiffOne("中国");
        model.addAttribute("regionList", list);
        model.addAttribute("Total", Total);
        model.addAttribute("diff", diff);
        return "China";

    }

    @RequestMapping("/showByCountry")
    public String showByCountry(@RequestParam(value = "country", defaultValue = "") String country, Model model){
        List list = null;
        if (country.equals("") || country == null)
            list = dataService.getAllData();
        else list = dataService.FindRegionDataByKey(country);
        int Total = dataService.getSumOne(country);
        int diff = dataService.getDiffOne(country);
        model.addAttribute("regionList", list);
        model.addAttribute("Total", Total);
        model.addAttribute("diff", diff);
        return "byCountry";
    }
}
